package com.dqhl.community.activity;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.adapter.RepairRecordPagerAdapter;
import com.dqhl.community.base.BaseActivity;

/**
 * Created by guanluocang on 2016/8/29.
 * RepairRecordActivity
 * 报修记录
 */
public class RepairRecordActivity extends BaseActivity implements View.OnClickListener {

    private ImageView iv_topBack;
    private TextView tv_repairLext;
    private ViewPager vp_repairRecord;
    private TextView tv_finish;
    private TextView tv_unfinish;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_repair_list);
        //实例化数据
        initView();
        //实例化下拉数据
//        getData();
    }



    private void initView() {
        iv_topBack = (ImageView) findViewById(R.id.iv_top_back);
        iv_topBack.setVisibility(View.VISIBLE);
        tv_repairLext = (TextView) findViewById(R.id.tv_top_title);
        tv_repairLext.setText(R.string.repair_record);
        iv_topBack.setOnClickListener(this);
        tv_unfinish = (TextView) findViewById(R.id.tv_unfinish);
        tv_unfinish.setOnClickListener(this);
        tv_finish = (TextView) findViewById(R.id.tv_finish);
        tv_finish.setOnClickListener(this);
        vp_repairRecord = (ViewPager) findViewById(R.id.vp_repairRecord);
        vp_repairRecord.setAdapter(new RepairRecordPagerAdapter(this.getSupportFragmentManager()));
        vp_repairRecord.setCurrentItem(0, true);
        vp_repairRecord.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        tv_unfinish.setTextColor(ContextCompat.getColor(RepairRecordActivity.this, R.color.item_location));
                        tv_finish.setTextColor(ContextCompat.getColor(RepairRecordActivity.this, R.color.appliance_color));
                        break;
                    case 1:
                        tv_unfinish.setTextColor(ContextCompat.getColor(RepairRecordActivity.this, R.color.appliance_color));
                        tv_finish.setTextColor(ContextCompat.getColor(RepairRecordActivity.this, R.color.item_location));
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.tv_finish:
                    vp_repairRecord.setCurrentItem(1,true);
                break;
            case R.id.tv_unfinish:
                    vp_repairRecord.setCurrentItem(0,true);
                break;
        }
    }





}
